#include <iostream>
#include "CamRTSPServer.h"
#include "INIReader.h"
#include "log.h"

int LogLevel;
int main()
{
    INIReader configs("./configs/config.ini");
    if (configs.ParseError() < 0) {
        printf("read config failed.");
        exit(1);
    } else {
        std::string level = configs.Get("log", "level", "NOTICE");
        if (level == "NOTICE") {
            initLogger(NOTICE);
        } else if (level == "INFO") {
            initLogger(INFO);
        } else if (level == "ERROR") {
            initLogger(ERROR);
        }
    }

    try {
       // 创建两个转码器实例，分别对应不同视频源
        auto transcoder1 = std::make_shared<TransCoder>("video1");
        auto transcoder2 = std::make_shared<TransCoder>("video2");
        
        // 创建两个服务器实例，分别推送到不同端口
        CamRTSPServer server1("server1");
        CamRTSPServer server2("server2");
        
        server1.addTranscoder(transcoder1);
        server2.addTranscoder(transcoder2);
        
        // 在不同线程中运行两个服务器
        std::thread t1([&server1]() {
            server1.run();
        });
        
        std::thread t2([&server2]() {
            server2.run();
        });
        
        t1.join();
        t2.join();
    } catch (const std::invalid_argument &err) {
        LOG(ERROR, err.what());
    }

    LOG(INFO, "test.");
    return 0;
}
